home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 March / EnigmA AMIGA RUN 05 (1996)(G.R. Edizioni)(IT)[!][issue 1996-03][Skylink CD IV].iso / earcd / music / ptsupp.lha / PT Support archive / Sources / PTCalcTime.S < prev    next >
Text File  |  1996-01-30  |  6KB  |  277 lines

  1.  
  2. Go        moveq.l    #0,d0
  3.         move.l    #25000/50,d1        ; 50Hz
  4.         moveq.l    #1,d2
  5.         lea.l    Module,a0
  6.         lea.l    Timer,a1
  7.         jsr    PTCalcTime
  8.  
  9.         moveq.l    #0,d0
  10.         rts
  11.  
  12. Timer        dc.l    0,0,0,0            ; Hours, Minutes,
  13.                         ; Seconds, 1/100s
  14.  
  15.     INCDIR    "m:Bjørn A Lynne/"
  16. Module    INCBIN    "mod.doin' the sushi"
  17.     EVEN
  18.  
  19. ;------------------------------------------------------------------------------
  20. ;
  21. ;    $VER: PTCalcTime v1.1 - by Håvard "Howard" Pedersen
  22. ;    © 1994-96 Mental Diseases
  23. ;
  24. ;    A program for calculating the playtime of ProTracker modules.
  25. ;
  26. ;    I cannot be held responsible for any damage caused directly or in-
  27. ;    directly by this code. Still, every released version is thouroughly
  28. ;    tested with Mungwall and Enforcer, official Commodore debugging tools.
  29. ;    These programs traps writes to unallocated ram and reads/writes to/from
  30. ;    non-ram memory areas, which should cover most bugs.
  31. ;
  32. ;    HISTORY:
  33. ;
  34. ;v1.0    Simple thingy with bugs and quirks. Did calculating using IRQ/second.
  35. ;
  36. ;v1.1    Bugfix version. Finally usable.
  37. ;    * Pattern loop wasn't sensed properly. By some reason I used effect
  38. ;      command E5 for set loop! (?)
  39. ;    * Entire pattern loop code was broken. Recoded, does now work correctly
  40. ;      with "mod.couldbe".
  41. ;    * Uses 1/25000th second between each interrupt for timing. Much more
  42. ;      accurate in CIA mode.
  43. ;    * Small speedups here and there.
  44. ;
  45. ;------------------------------------------------------------------------------
  46. ;
  47. ;    PUBLIC FUNCTIONS:
  48. ;
  49. ;Function:    PTCalcTime(SongPos,delay,CIA(BOOL),Module,TimerStruct)
  50. ;        (D0,D1,D2,A0,A1)
  51. ;Purpose:    Calculates exact playtime of a ProTracker module.
  52. ;------------------------------------------------------------------------------
  53.  
  54. ;------------------------------------------------------------------------------
  55. ;            PTCALCTIME
  56. ;------------------------------------------------------------------------------
  57. ; D0 - Local use
  58. ; D1 - 25000th of a second delay between each IRQ
  59. ; D2 - Local use
  60. ; D3 - Pattern delay count
  61. ; D4 - Local use
  62. ; D5 - 
  63. ; D6 - 
  64. ; D7 - Voiceloop count
  65. ; A0 - Module
  66. ; A1 - TimerStruct
  67. ; A2 - PatternPosition
  68. ; A3 - Local use
  69. ; A4 - 
  70. ; A5 - 
  71. ; A6 - 
  72. PTCalcTime    move.l    #6,.Speed
  73.         move.l    #0,.PattPos
  74.         move.l    d0,.SongPos
  75.         move.l    #0,.PattLoopPos
  76.         move.l    #0,.PosJumpPos
  77.         move.b    d2,.CIAFlag
  78.  
  79. .MainLoop    lea.l    952(a0),a2        ; Get position
  80.         add.l    .SongPos,a2
  81.         moveq.l    #0,d0
  82.         move.b    (a2),d0            ; Get pattern at current pos
  83.         lsl.l    #8,d0            ; *1024
  84.         lsl.l    #2,d0
  85.         lea.l    1084(a0),a2
  86.         add.l    d0,a2            ; Address for pattern
  87.  
  88. .StepLoop    lea.l    952(a0),a2        ; Get position
  89.         add.l    .SongPos,a2
  90.         moveq.l    #0,d0
  91.         move.b    (a2),d0            ; Get pattern at current pos
  92.         lsl.l    #8,d0            ; *1024
  93.         lsl.l    #2,d0
  94.         lea.l    1084(a0),a2
  95.         add.l    d0,a2            ; Address for pattern
  96.  
  97.         move.l    .PattPos,d0
  98.         lsl.l    #4,d0
  99.         add.l    d0,a2
  100.  
  101.         moveq.l    #4-1,d7            ; Loop
  102. .VoiceLoop    lea.l    .CmdsTab,a3
  103.         move.l    (a2),d0            ; Get stuff
  104.         and.l    #$00000ff0,d0        ; Get command
  105.  
  106.         move.l    d0,d2
  107.         and.l    #$00000f00,d2
  108.         cmp.l    #$00000e00,d2        ; Misc cmds?
  109.         beq.s    .TabLoop
  110.  
  111.         and.l    #$00000f00,d0
  112.  
  113. .TabLoop    cmp.l    #-1,(a3)
  114.         beq.s    .NoneFound
  115.  
  116.         cmp.l    (a3),d0
  117.         bne.s    .NoMatch
  118.  
  119.         move.l    4(a3),a3
  120.         jsr    (a3)
  121.         bra.s    .NoneFound
  122.  
  123. .NoMatch    addq.l    #8,a3
  124.         bra.s    .TabLoop
  125.  
  126. .NoneFound    addq.l    #4,a2
  127.         dbf    d7,.VoiceLoop
  128.  
  129.         bsr.w    .AddSpeed
  130.  
  131.         addq.l    #1,.PattPos
  132.  
  133.         tst.b    .BreakFlag
  134.         bne.s    .NewPos
  135.  
  136.         cmp.l    #64,.PattPos
  137.         bne.w    .StepLoop
  138.  
  139. .NewPos        move.b    #0,.BreakFlag
  140.  
  141.         move.l    .PattBreakPos,.PattPos
  142.         move.l    #0,.PattBreakPos    ; Default pattern break pos
  143.  
  144.         tst.l    .PosJumpPos
  145.         beq.s    .NoPosJump
  146.  
  147.         move.l    .PosJumpPos,.SongPos
  148.         move.l    #0,.PosJumpPos
  149.         bra.s    .EndIt
  150.  
  151. .NoPosJump    add.l    #1,.SongPos
  152.         move.l    .SongPos,d0
  153.         lea.l    950(a0),a3
  154.         cmp.b    (a3),d0
  155.         blo.w    .MainLoop
  156.  
  157. .EndIt        move.l    12(a1),d0
  158.         divu.w    #250,d0
  159.         and.l    #$ffff,d0
  160.         move.l    d0,12(a1)        ; Convert to 100/s.
  161.  
  162.         rts
  163.  
  164. .AddSpeed    move.l    .Speed,d0
  165.         subq.l    #1,d0
  166. .SpeedLoop    add.l    d1,12(a1)
  167.         dbf    d0,.SpeedLoop
  168. .AddSpeedLoop    cmp.l    #25000,12(a1)
  169.         blo.s    .OkIRQs
  170.         sub.l    #25000,12(a1)
  171.         add.l    #1,8(a1)
  172. .OkIRQs        cmp.l    #60,8(a1)
  173.         blo.s    .OkSecs
  174.         sub.l    #60,8(a1)
  175.         add.l    #1,4(a1)
  176. .OkSecs        cmp.l    #60,4(a1)
  177.         blo.s    .OkMins
  178.         sub.l    #60,4(a1)
  179.         add.l    #1,(a1)
  180. .OkMins        rts
  181.  
  182. .CmdsTab    dc.l    $00000b00,._PosJump
  183.         dc.l    $00000d00,._PattBreak
  184.         dc.l    $00000f00,._SetSpeed
  185.         dc.l    $00000e60,._PatLoop
  186.         dc.l    $00000ee0,._PatDelay
  187.         dc.l    -1,-1
  188.  
  189. ._PosJump    move.l    (a2),d0            ; Get stuff
  190.         and.l    #$ff,d0
  191.         move.l    d0,.PosJumpPos
  192.         move.b    #-1,.BreakFlag
  193.         rts
  194.  
  195. ._PattBreak    move.l    (a2),d0            ; Get stuff
  196.         and.l    #$ff,d0
  197.         move.l    d0,.PattBreakPos
  198.         move.b    #-1,.BreakFlag
  199.         rts
  200.  
  201. ._SetSpeed    move.l    (a2),d0            ; Get stuff
  202.         and.l    #$ff,d0
  203.         beq.s    .Halt
  204.  
  205.         tst.b    .CIAFlag
  206.         beq.s    .VBL
  207.  
  208.         cmp.b    #$20,d0
  209.         blo.s    .VBL
  210.  
  211.         ; Do some CIA->Hz converting!
  212.         move.l    #62500,d1
  213.         divu.w    d0,d1
  214.         and.l    #$ffff,d1
  215.  
  216.         rts
  217.  
  218. .VBL        move.l    d0,.Speed
  219.         rts
  220.  
  221. .Halt        move.l    #-1,.PosJumpPos        ; Halt module
  222.         move.b    #-1,.BreakFlag
  223.         rts
  224.  
  225. ._PatLoop    move.l    (a2),d0            ; Get stuff
  226.         and.l    #$f,d0
  227.         tst.l    d0
  228.         beq.s    .SetLoop
  229.  
  230.         tst.l    .PattLoopCnt
  231.         beq.s    .SetLoopCnt
  232.  
  233.         subq.l    #1,.PattLoopCnt
  234.         bne.s    .DoLoop
  235.  
  236.         rts
  237.  
  238. .SetLoop    move.l    .PattPos,.PattLoopPos
  239.         rts
  240.  
  241. .SetLoopCnt    move.l    d0,.PattLoopCnt
  242.  
  243. .DoLoop        move.l    .PattLoopPos,.PattBreakPos; Force loop
  244.         sub.l    #1,.SongPos
  245.         move.b    #-1,.BreakFlag
  246.  
  247.         rts
  248.  
  249. .PattLoopIt    subq.l    #1,.PattLoopCnt
  250.         tst.l    .PattLoopCnt
  251.         beq.s    .Return
  252.  
  253.         move.l    .PattLoopPos,.PattPos
  254. .Return        rts
  255.  
  256. ._PatDelay    move.l    (a2),d0            ; Get stuff
  257.         and.l    #$f,d0
  258.         tst.l    d0
  259.         beq.s    .PatDelNo
  260.         subq.l    #1,d0
  261.         move.l    d0,d3
  262. .PatDelLoop    bsr.w    .AddSpeed
  263.         dbf    d3,.PatDelLoop
  264. .PatDelNo    rts
  265.  
  266. .BreakFlag    dc.b    0
  267. .CIAFlag    dc.b    0
  268.     EVEN
  269. .Speed        dc.l    0
  270. .PattPos    dc.l    0
  271. .SongPos    dc.l    0
  272. .PattLoopPos    dc.l    0
  273. .PattLoopCnt    dc.l    0
  274. .PosJumpPos    dc.l    0
  275. .PattBreakPos    dc.l    0
  276.  
  277.